package br.com.ds3.relatorio.util;

import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import br.com.ds3.model.Inscricao;

public class InscricaoDatasource implements JRDataSource {
	private Iterator<Inscricao> inscricoes;
	private Inscricao inscricao;
	
	public InscricaoDatasource(List<Inscricao> inscricoes) {
		this.inscricoes = inscricoes.iterator();
	}

	@Override
	public Object getFieldValue(JRField field) throws JRException {
		if (field.getName().equals("nomeEvento")) {
			return inscricao.getEvento().getNome();
		} else if (field.getName().equals("nomeParticipante")) {
			return inscricao.getParticipante().getNome();
		} else if (field.getName().equals("cpf")) {
			return inscricao.getParticipante().getCpf();
		} else if (field.getName().equals("situacao")) {
			return inscricao.getSituacao();
		} else if (field.getName().equals("dataEvento")) {
			return new SimpleDateFormat("dd/MM/yyyy").format(inscricao.getAtividade().getData());
		} else if (field.getName().equals("localEvento")) {
			return inscricao.getEvento().getEndereco();
		} 
		return null;
	}

	@Override
	public boolean next() throws JRException {
		boolean retorno = inscricoes.hasNext();
		
		if (retorno) {
			inscricao = inscricoes.next();
		}
		
		return retorno;
	}
}
